package com.laicar.geekbank;

import android.content.Intent;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SplashActivity extends AppCompatActivity {
    public static final String TITLE = "title";
    public static final String USER_INFO = "userInfo";
    public static final int REQUEST_CODE = 9999;
    public static final String TAG =SplashActivity.class.getSimpleName();
    Handler mHandler = new Handler();
    private TextView mTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);


        mTextView=findViewById(R.id.title_txtView);

        final String title = mTextView.getText().toString();


        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                UserInfo info =new UserInfo("akluse",20);
                Intent intent=new Intent(SplashActivity.this,MainActivity.class);

                intent.putExtra(TITLE,title);
                intent.putExtra(USER_INFO,info);
                startActivityForResult(intent, REQUEST_CODE);
            }
        },1000);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==REQUEST_CODE && resultCode==MainActivity.RESULT_CODE){
            if(data!=null){
                String title = data.getStringExtra(TITLE);
                mTextView.setText(title);
            }
        }
    }
}
